

import { readFileSync } from 'fs'
import { resolve } from 'path';
let jsonData: object | null = null
export default defineEventHandler(() => {
  try {
    if (!jsonData) {
      // 解析 assets 目录的绝对路径
      const filePath = resolve('app/assets/song.json');
      // console.log(filePath)
      // 读取文件内容
      const data = readFileSync(filePath, 'utf-8');
      // 解析 JSON
      jsonData = JSON.parse(data);
    }
    return jsonData;
  } catch (error) {
    throw createError({
      statusCode: 500,
      message: 'Failed to read JSON file',
    });
  }
})
